#include"chen.h"

int
main( int argc, char **argv )
{
	int sockfd;
	socklen_t len;
	struct sockaddr_un addr1, addr2;

	if ( argc != 2 )
		err_quit( "usage:unixbind <pathname>" );

	sockfd = Socket( AF_LOCAL, SOCK_STREAM, 0 );

	unlink( argv[1] );

	bzero( &addr1, sizeof( addr1 ) );

	strncpy( addr1.sun_path, argv[1], sizeof( addr1.sun_path ) - 1 );
	Bind( sockfd, ( struct sockaddr * )&addr1, sizeof( addr1 ) );

	len = sizeof( addr2 );
	getsockname( sockfd, ( struct sockaddr * )&addr2, &len );

	fprintf(stdout, "bound name = %s, returned len = %d\n", addr2.sun_path, len );

	return 0;
}
